package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.Random;


@RestController
public class UserController {
   @Autowired
   private UserService userService;
   @PostMapping("/user/sendMsg")
   public ResultInfo sendMsg(@RequestBody Map<String,String>  phoneNum){
       //接收手机号
       String phone = phoneNum.get("phone");
       //调用service发送短信
       userService.sendMag(phone);
       //返回结果
       return ResultInfo.success();

   }
    // 用户登录
    @PostMapping("/user/login")
    public ResultInfo login(@RequestBody Map<String,String> map){//接收参数
        // 1.接收参数
        String phone = map.get("phone");
        String code = map.get("code");
        // 2.调用service
        ResultInfo resultInfo=userService.login(phone,code);
        // 3.返回结果
        return resultInfo;
    }



}
